#include "Deck.h"

void InitDeck(Deck &deck) {
	deck.nb = DECK_MAX_NUMBER;
	//i = Kind
	for (int i = 0; i < 4; i++) {
		Kind k;
		GetKind(k, i);
		//j = Value
		for (int j = 0; j < 13; j++) {
			InitCard(deck.cards[i*13 + j], j + 2, k);
		}
	}
}

void InitIndex(DeckIndex &deckIndex) {
	deckIndex.nb = DECK_MAX_NUMBER;
	for (int i = 0; i < DECK_MAX_NUMBER; i++) {
		deckIndex.index[i] = i;
	}
}

void GetKind(Kind &k, int i) {
	switch (i) {
	case 0:
		k = SPADE;
		break;
	case 1:
		k = HEART;
		break;
	case 2:
		k = CLUB;
		break;
	default:
		k = DIAMOND;
		break;
	}
}

void GetCard(Card &drawedCard, const Deck &deck, DeckIndex &deckIndex) {
	int randCard = rand() % deckIndex.nb;
	drawedCard = deck.cards[deckIndex.index[randCard]];
	deckIndex.index[randCard] = deckIndex.index[deckIndex.nb];
	deckIndex.nb--;
}

